﻿using System;
using System.Collections.Generic;
using System.Drawing;
using Xlsx.ComponentModel;
using Xlsx.ComponentModel.DataAnnotations;
using Xlsx.ComponentModel.Enums;

namespace Xlsx.DataBinder.Samples
{
    [XlsxBindable]
    public class XlsxTestClass
    {
        [XlsxBindableProperty(XlsxDataType.Numeric, "Identifiant")]
        public int Id { get; set; }

        [XlsxBindableProperty(XlsxDataType.String, "Nom", 1)]
        public string Name { get; set; }

        [XlsxBindableProperty(XlsxDataType.String, "Email", 2)]
        public string Email { get; set; }

        [XlsxBindableProperty(XlsxDataType.DateTime, "Subscribe", 3)]
        public DateTime SubscibreDate { get; set; }

        [XlsxBindableProperty(XlsxDataType.Boolean, "Active", 4)]
        public bool IsActive { get; set; }
    }

    class Program
    {
        static void Main()
        {
            #region Data object
            var test1 = new XlsxTestClass
                {
                Id = 1,
                Name = "Sylvain",
                Email = "sylvain@email.com",
                IsActive = true,
                SubscibreDate = new DateTime(2011, 10, 5)
            };

            var test2 = new XlsxTestClass
                {
                Id = 2,
                Name = "Nicolas",
                Email = "nicolas@email.com",
                IsActive = true,
                SubscibreDate = new DateTime(2012, 2, 23)
            };

            var test3 = new XlsxTestClass
                {
                Id = 3,
                Name = "Damien",
                Email = "damien@email.com",
                IsActive = false,
                SubscibreDate = new DateTime(2010, 5, 12)
            };

            var lists = new List<XlsxTestClass> {test1, test2, test3};

            #endregion

            #region Skin definition
            var skinHeader = new XlsxSkin
                {
                BorderColor = Color.Black,
                BorderStyle = XlsxBorderStyle.Medium,
                FillColor = Color.FromArgb(255, 0, 122, 204),
                FontColor = Color.White,
                FontSize = 10,
                HasBorder = true,
                IsBold = true,
                IsItalic = false,
                IsUnderline = false
            };

            var skinRow = new XlsxSkin
                {
                BorderColor = Color.Black,
                BorderStyle = XlsxBorderStyle.Simple, 
                FillColor = Color.FromArgb(255, 158, 158, 158),
                FontColor = Color.Black,
                FontSize = 10,
                HasBorder = true,
                IsBold = false,
                IsItalic = false,
                IsUnderline = false
            };

            var skinAlternate = new XlsxSkin
                {
                BorderColor = Color.Black,
                BorderStyle = XlsxBorderStyle.None, 
                FillColor = Color.FromArgb(255, 104, 104, 104),
                FontColor = Color.White,
                FontSize = 10,
                HasBorder = true,
                IsBold = false,
                IsItalic = false,
                IsUnderline = false
            };

            XlsxSkinManager.Load(skinHeader, skinRow, skinAlternate);
            #endregion

            var dataSheet = new XlsxDataSheet<XlsxTestClass>
                { 
                SheetId =1,
                Name = "Users",
                Data = lists
            };

            var binder = new XlsxDataBinder<XlsxTestClass>
                { 
                DataSource = dataSheet
            };

            binder.DataBind();

            binder.Save("doc", "test");
        }
    }
}
